package com.cm.caseManagement.controller;


import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmCostExpense;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmCostExpenseService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用报销Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/expense")
public class CmCostExpenseController extends BaseController
{
    @Autowired
    private ICmCostExpenseService cmCostExpenseService;

    /**
     * 查询费用报销列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmCostExpense cmCostExpense)
    {
        startPage();
        List<CmCostExpense> list = cmCostExpenseService.selectCmCostExpenseList(cmCostExpense);
        return getDataTable(list);
    }

    /**
     * 导出费用报销列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:export')")
    @Log(title = "费用报销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmCostExpense cmCostExpense)
    {
        List<CmCostExpense> list = cmCostExpenseService.selectCmCostExpenseList(cmCostExpense);
        ExcelUtil<CmCostExpense> util = new ExcelUtil<CmCostExpense>(CmCostExpense.class);
        util.exportExcel(response, list, "费用报销数据");
    }

    /**
     * 获取费用报销详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmCostExpenseService.selectCmCostExpenseById(id));
    }

    /**
     * 新增费用报销
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:add')")
    @Log(title = "费用报销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmCostExpense cmCostExpense)
    {
        return toAjax(cmCostExpenseService.insertCmCostExpense(cmCostExpense));
    }

    /**
     * 修改费用报销
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:edit')")
    @Log(title = "费用报销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmCostExpense cmCostExpense)
    {
        return toAjax(cmCostExpenseService.updateCmCostExpense(cmCostExpense));
    }

    /**
     * 删除费用报销
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:expense:remove')")
    @Log(title = "费用报销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmCostExpenseService.deleteCmCostExpenseByIds(ids));
    }
}
